<?php
/**
 * Author:   tangxiaowen
 * Email:    846506584@qq.com
 * Date:     2019/4/9 0009
 * Describe: 公共系统类
 */

namespace app\common\controller;
use think\Controller;
use think\Request;
use think\Log;
use think\Db;
class Fengkong extends Controller
{
	 public function __construct()
    {
        parent::__construct();
    }
	
     /**
     * 风控接口
     */
    public function fengkong_jiuwei($userId)
    {
    	
		$user =Db::table('xb_mem_info')->where('ID',$userId)->find();
		$model_name=Db::table('xb_sys_inteparameter')->where(['ParaName'=>'model_name1'])->value('ParaValue');//商户号
        $fkData['model_name']=$model_name; //模型名
        $fkData['product'] = model('System')->getSystemInfo()['duanxinqianming'];
        $fkData['apply_time']=date('Y-m-d H:i:s'); //时间
        $fkData['mobile']= $user['Mobile'];
        $fkData['name']=$user['TrueName'];
        $fkData['idcard']=$user['IDCard'];
		$social = Db::table('xb_renzen_social')->where('UserID',$userId)->find();
        if(!$social){
        	echo '获取用户社交数据失败';
        } 
        $phoneList =json_decode($social['Phonelist'],1);
        $fkData['contact']=$phoneList;  //手机通讯录
        $fkData['user_address']=empty($social['address'])?$social['address']:'杭州' . empty($social['ad_detail'])?$social['ad_detail']:'杭州西湖区1栋';
        //紧急联系人
        $fkData['e_contacts'][0]['contact_name']=$social['person_one'];
        $fkData['e_contacts'][0]['contact_phone']=$social['person_one_mobile'];
        $fkData['e_contacts'][1]['contact_name']=$social['person_two'];
        $fkData['e_contacts'][1]['contact_phone']=$social['person_two_mobile'];
        $dataOrigin = Db::table('xb_moxie_origin')->where('UserID',$userId)->value('OriginData');
        $dataReport = Db::table('xb_moxie_report')->where('UserID',$userId)->value('ReportData');
        $fkData['carrier_data']['mx_raw']=$dataOrigin;
        $fkData['carrier_data']['mx_report']=$dataReport;
        $da = json_encode($fkData,JSON_UNESCAPED_UNICODE);
        $url = 'http://47.93.185.26/risk/gzip/';
        $datas=gzencode($da);
        $realScore =httpPost($datas,$url);
        $resArray = json_decode($realScore,true);
        if($resArray['score'] == 0){
            $resArray['score'] = 0;
            $result3 = json_encode($resArray,JSON_UNESCAPED_UNICODE);
        }else{
            $resArray['score'] = sprintf('%.2f',$resArray['score']);
            $result3 = json_encode($resArray,JSON_UNESCAPED_UNICODE);
        }
        return $result3;
    }
	
	

}